package com.vhans.aapi.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.core.web.page.TableDataInfo;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.friend.FriendDTO;
import com.vhans.db.model.vo.friend.FriendInfoVO;
import com.vhans.db.model.vo.friend.FriendVO;
import com.vhans.db.service.ICFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 好友Controller控制器
 *
 * @author vhans
 * @date 2023-05-21
 */
@Api(tags = "好友模块")
@RestController
@RequestMapping("/admin/friend")
public class FriendController extends BaseController {
    @Autowired
    private ICFriendService cFriendService;

    /**
     * 查询好友列表
     *
     * @param condition 条件
     * @return {@link FriendVO} 题目列表
     */
    @ApiOperation(value = "查询好友列表")
    @SaCheckPermission("chat:friend:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<FriendVO> list = cFriendService.selectCFriendVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取好友详细信息
     *
     * @param id 好友id
     * @return {@link Result<FriendInfoVO>} 好友信息
     */
    @ApiOperation(value = "获取好友编辑信息")
    @SaCheckPermission("chat:friend:query")
    @GetMapping(value = "/info/{id}")
    public Result<FriendInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(cFriendService.selectCFriendInfoById(id));
    }

    /**
     * 新增好友
     *
     * @param cFriend 好友信息
     * @return {@link Result<>}
     */
    @ApiOperation(value = "新增好友")
    @SaCheckPermission("chat:friend:add")
    @PostMapping("/add")
    public Result<?> add(@Validated @RequestBody FriendDTO cFriend) {
        cFriendService.insertFriend(cFriend);
        return Result.success();
    }

    /**
     * 修改好友
     */
    @ApiOperation(value = "修改好友")
    @SaCheckPermission("chat:friend:update")
    @PutMapping("/update")
    public Result<?> update(@Validated @RequestBody FriendDTO friend) {
        return toAjax(cFriendService.updateCFriend(friend));
    }

    /**
     * 删除好友
     *
     * @param friend 需要删除的好友
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除好友")
    @SaCheckPermission("chat:friend:delete")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestBody FriendDTO friend) {
        return toAjax(cFriendService.deleteFriend(friend));
    }
}
